package android.tusnotas.parser;

import java.util.ArrayList;
import java.util.List;

import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.XPatherException;

import android.tusnotas.beans.Instance;
import android.tusnotas.exception.ProcessingInstancesException;

import com.thoughtworks.xstream.XStream;

public class WebServiceParser implements TusNotasParser {

	private List<Instance> instances = new ArrayList<Instance>();

	/* (non-Javadoc)
	 * @see android.tusnotas.parser.TusNotasParser#initializeHtmlCleaner()
	 */
	public HtmlCleaner initializeHtmlCleaner(){

		HtmlCleaner cleaner = new HtmlCleaner();
		CleanerProperties props = cleaner.getProperties();
		props.setAllowHtmlInsideAttributes(Boolean.TRUE);
		props.setAllowMultiWordAttributes(Boolean.TRUE);
		props.setRecognizeUnicodeChars(Boolean.TRUE);
		props.setOmitComments(Boolean.FALSE);
		return cleaner;

	}

	/* (non-Javadoc)
	 * @see android.tusnotas.parser.TusNotasParser#parseHTML(java.lang.String)
	 */
	@Override
	public List<Instance> parseXML(String XML) throws ProcessingInstancesException, XPatherException{

		XStream stream = new TusNotasXStream();
		
		@SuppressWarnings("unchecked")
		List<Instance> instances = ((List<Instance>) stream.fromXML(XML));
		
		return instances;

	}

	/* (non-Javadoc)
	 * @see android.tusnotas.parser.TusNotasParser#setInstances(java.util.List)
	 */
	@Override
	public void setInstances(List<Instance> instances) {
		this.instances = instances;
	}

	/* (non-Javadoc)
	 * @see android.tusnotas.parser.TusNotasParser#getInstances()
	 */
	@Override
	public List<Instance> getInstances() {
		return instances;
	}
}
